<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@ page import ="java.sql.*, java.util.*" %>
<%@ include file="db.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
String name = request.getParameter("name");
String pass = request.getParameter("pass");
String email = request.getParameter("email");
String title = request.getParameter("title");
String contents = request.getParameter("contents");

PreparedStatement pstmt1 = null, pstmt2 = null;

Calendar dateIn = Calendar.getInstance();
String indate = Integer.toString(dateIn.get(Calendar.YEAR)) + "-";
indate = indate + Integer.toString(dateIn.get(Calendar.MONTH)+1) + "-";
indate = indate + Integer.toString(dateIn.get(Calendar.DATE)) + " ";
indate = indate + Integer.toString(dateIn.get(Calendar.HOUR_OF_DAY)) + ":";
indate = indate + Integer.toString(dateIn.get(Calendar.MINUTE)) + ":";
indate = indate + Integer.toString(dateIn.get(Calendar.SECOND));

String strSQL = "SELECT Max(num) FROM s_store";
pstmt1 = conn.prepareStatement(strSQL);
ResultSet rs = pstmt1.executeQuery();
int num = 1;

if(!rs.wasNull())
{
	rs.next();
	num = rs.getInt(1) +1;
}
strSQL = "INSERT INTO s_store(num,name,pass,email,title,contents,writedate,readcount) VALUES(?,?,?,?,?,?,?,?)";
pstmt2 = conn.prepareStatement(strSQL);
pstmt2.setInt(1 , num);
pstmt2.setString(2 , name);
pstmt2.setString(3 , pass);
pstmt2.setString(4 , email);
pstmt2.setString(5 , title);
pstmt2.setString(6 , contents);
pstmt2.setString(7 , indate);
pstmt2.setInt(8, 0);
pstmt2.executeUpdate();

rs.close();
pstmt1.close();
pstmt2.close();
conn.close();

response.sendRedirect("store.jsp");

%>
